<script>
import { getBannerList, delBanner } from '../../api/banner';
export default {
  name: 'BannerList',
  data () {
    return {
      bannerList: [],
      currentPage: 1
    }
  },
  computed: {
    computedTableData () {
      return this.bannerList.slice((this.currentPage - 1) * 4, (this.currentPage - 1) * 4 + 4)
    }
  },
  mounted () {
    getBannerList().then(res => {
      this.bannerList = res.data
    })
  },
  methods: {
    delClick (row) {
      delBanner({ bannerid: row.bannerid }).then(res => {
        getBannerList().then(res => {
          this.bannerList = res.data
        })
      })
    }
  }
}
</script>
<template>
  <div>
    <p>轮播图列表</p>
    <el-table :data="computedTableData">
      <el-table-column type="index" label="序号" width="80" />

      <el-table-column prop="img" label="图片">
        <template #default="scope">
          <div>
            <el-image :src="scope.row.img"></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="alt" label="提示信息" />
      <el-table-column prop="bannerid" label="id" />
      <el-table-column label="操作">
        <template #default="scope">
          <div>
            <el-button @click="delClick(scope.row)">删除</el-button>
          </div>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination background layout="prev, pager, next" :page-size="4" :total="bannerList.length"
      v-model:current-page="currentPage" />
  </div>
</template>
<style lang="scss" scoped>
.el-image {
  width: 160px;
}
</style>
